package com.lebang.controller.sys;

import com.lebang.aop.ConfigRecord;
import com.lebang.common.Login;
import com.lebang.domain.PromotionRewardSetting;
import com.lebang.service.AdSettingService;
import com.lebang.service.LuckDrawService;
import com.lebang.service.MasterSettingService;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;

/**
 * @Author: hwq
 * @Date: 2019/11/26 16:16
 * @Version 1.0
 */
@Api(tags = "抽奖活动")
@RequestMapping("/sys/master")
@Controller
public class SysMasterSettingController {
    @Autowired
    private AdSettingService adSettingService;
    @Autowired
    private MasterSettingService settingService;

    @Autowired
    private LuckDrawService luckDrawService;


    @GetMapping("/draw/list")
    @Login
    public String drawlist(Integer id, Model model) {
        return "/master/setting";
    }

    @GetMapping("/draw/add")
    @Login
    public String drawadd(Integer id, Model model) {
        PromotionRewardSetting setting;
        if (id != null) {
            setting = settingService.selectById(id);
        } else {
            setting = new PromotionRewardSetting();
        }
        model.addAttribute("item", setting);
        return "/master/setting-add";
    }

    @PostMapping("/draw/edit")
    @Login
    @ResponseBody
    @ConfigRecord
    public JsonData drawedit(PromotionRewardSetting sort) {
        if (sort.getId() != null) {

            settingService.updateById(sort);
        } else {
            sort.setCreateTime(LocalDateTime.now());

            settingService.insertModel(sort);
        }
        return Callback.success("success", "修改成功");
    }
}

